AnnieRoot.ui = AnnieRoot.ui || {};
ui.RopeTimes = function () {
    var s = this;
    annie.Sprite.call(s);
    /*_a2x_need_start*/s.num=null;/*_a2x_need_end*/
    annie.initRes(s, "ui", "RopeTimes");
    //your code here
    var ropeNum = 2;//默认值
    s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
        //自适应调整
        // trace('viewY:' + s.stage.viewRect.y);
        // alert(s.stage.viewRect.y + s.stage.viewRect.height - s.height + 10);
        s.y = s.stage.viewRect.y + s.stage.viewRect.height - 100 - 20;
        if (gameGlobalData.initGameData && gameGlobalData.initGameData.sum) {
            //设置游戏初始化绳索数
            ropeNum = parseInt(gameGlobalData.initGameData.sum);
            s.num.gotoAndStop(ropeNum + 1);
        }
    });
    annie.globalDispatcher.addEventListener('setGameInitRopeTimes', function (e) {
        //设置游戏初始化绳索数
        var initRopeNum = parseInt(e.data.index);
        s.num.gotoAndStop(initRopeNum + 1);
    });
    //更新绳索次数
    annie.globalDispatcher.addEventListener('updateRopeTimes', function (e) {
        // var type = e.data.type;
        ropeNum = parseInt(gameGlobalData.initGameData.sum);
        if (ropeNum > 0) {
            ropeNum--;
            gameGlobalData.initGameData.sum = ropeNum;//递减
            if (ropeNum == 0) {
                // trace('gameOver');
                gameGlobalData.isGameOver = true;
                //绳索用完，一局游戏结束
                annie.globalDispatcher.dispatchEvent('gameOver');
            }
        }
        s.num.gotoAndStop(ropeNum + 1);
    })
};
A2xExtend(ui.RopeTimes, annie.Sprite);
